<script>
    function fn1(x) {
        return x + 1;
    }
    function fn2(x) {
        return x + 2;
    }
    function fn3(x) {
        return x + 3;
    }
    function fn4(x) {
        return x + 4;
    }
    console.log(fn4(fn3(fn2(fn1(1)))));
    // 如何实现组合函数
    function mlcompose(...fn) {
        if (fn.length === 0) return num => num
        if (fn.length === 1) return fn[0]
        return fn.reduce((pre, next) => {
            return (num) => {
                return next(pre(num))
            }
        });
    }
    const a = mlcompose(fn1, fn2, fn3, fn4);
    console.log(a);
    console.log(a(1)); 
</script>